package com.wenli.lt.controller;


import com.wenli.lt.entity.Information;
import com.wenli.lt.service.IInformationService;
import com.wenli.lt.util.CommonResponse;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lt
 * @since 2021-03-24
 */
@RestController
@RequestMapping("information")
@Api(tags="信息")
public class InformationController {

    @Autowired
    IInformationService iInformationService;

    @GetMapping("getInformationsList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "studentNumber",value = "学生学号")
    })
    @ApiOperation("根据学号查询消息")
    public CommonResponse getInformationsList(String studentNumber){
        List<Information> informationList = iInformationService.getInformationsList(studentNumber);
        return new CommonResponse(informationList);
    }


    @PostMapping("setRead")
    @ApiOperation("设置已读")
    public CommonResponse setRead(@RequestBody  @ApiParam(name = "informationIds",value = "消息 List<String> 类型", required = true ) List<String> informationIds){
        iInformationService.setRead(informationIds);
        return new CommonResponse("设置成功!");
    }

    @PostMapping("AddInformation")

    @ApiOperation("回复消息(发送消息)")
    public CommonResponse AddInformation(@RequestBody @ApiParam(name = "information",value = "消息")Information information){
        Boolean aBoolean = iInformationService.AddInformation(information);
        if(aBoolean){
            return new CommonResponse("发送成功!");
        }else {
            return new CommonResponse(CommonResponse.ERROR_CODE,"数据出错,请联系管理员");
        }
    }
    

}
